﻿Type.registerNamespace('MS.InformationManagement.Common');
MS.InformationManagement.Common.StatusID = '';
MS.InformationManagement.Common.TimeOutID = '';

MS.InformationManagement.Common.GetCookie = function (name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == name) {
            return unescape(y);
        }
    }
}

MS.InformationManagement.Common.SetCookie = function (name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = name + "=" + c_value;
}

MS.InformationManagement.Common.ShowLoadingNotification = function (message) {
    ExecuteOrDelayUntilScriptLoaded(function () {
        return SP.UI.Notify.addNotification("Por favor espere...", true);
    }, 'sp.js');
}

MS.InformationManagement.Common.ShowStatus = function (message, color, timeoutDelay) {
    ExecuteOrDelayUntilScriptLoaded(function () {
        if (MS.InformationManagement.Common.StatusID && MS.InformationManagement.Common.StatusID != '') {
            SP.UI.Status.removeStatus(MS.InformationManagement.Common.StatusID);
            MS.InformationManagement.Common.StatusID = '';
            //clearTimeout(MS.InformationManagement.Common.TimeOutID);
        }
        MS.InformationManagement.Common.StatusID = SP.UI.Status.addStatus('', message);
        SP.UI.Status.setStatusPriColor(MS.InformationManagement.Common.StatusID, color);
        /*if (!timeoutDelay) { timeoutDelay = 3000; }
        MS.InformationManagement.Common.TimeOutID = setTimeout(
        function () {
            if (MS.InformationManagement.Common.StatusID && MS.InformationManagement.Common.StatusID != '') {
                SP.UI.Status.removeStatus(MS.InformationManagement.Common.StatusID);
                MS.InformationManagement.Common.StatusID = '';
            }
        }
        , timeoutDelay);*/
    }, 'sp.js');
}

MS.InformationManagement.Common.HideNotification = function (notificationID) {
    ExecuteOrDelayUntilScriptLoaded(function () {
        SP.UI.Notify.removeNotification(notificationID);
    }, 'sp.js');
}

MS.InformationManagement.Common.IsHoliday = function (datetime) {
    {
        var isHoliday = false;
        var data = { date: datetime };
        $.ajax({
            url: "/sites/docs/_vti_bin/MS.InformationManagement.Services/DocumentSchedulerService.asmx/IsHoliday",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(data), async: false,
            success: function (result, status) {
                isHoliday = result.d;
            },
            contentType: "application/json; charset=\"utf-8\""
        });
        return isHoliday;
    }
}

MS.InformationManagement.Common.FetchHolidays = function (startDate, endDate) {
    {
        var holidayArray = null;
        var data = { startDate: startDate, endDate: endDate };
        $.ajax({
            url: "/sites/docs/_vti_bin/MS.InformationManagement.Services/DocumentSchedulerService.asmx/GetHolidays",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(data), async: false,
            success: function (result, status) {
                holidayArray = result.d;
            },
            contentType: "application/json; charset=\"utf-8\""
        });
        return holidayArray;
    }
}